package com.bsoft.exchange.controller.clinicMedication;

import com.bsoft.exchange.domain.*;
import com.bsoft.exchange.pojo.*;
import com.bsoft.exchange.response.ResponseEntity;
import com.bsoft.exchange.service.ClinicMedicationService;
import com.bsoft.exchange.util.BaseResponse;
import com.bsoft.exchange.util.Constant;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * 门诊用药的接口
 */

@RestController
@RequestMapping(value = "webCloudClinic")
public class ClinicMedicationController {
	@Autowired
	private ClinicMedicationService clinicMedicationService;
	
	@ApiOperation(value = "获取药房药品信息")
	@RequestMapping(value = "/syncDrugInformation",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<SyncDrugInformationDomain> syncDrugInformation(@RequestBody  SyncDrugInformationPojo syncDrugInformationPojo)  {
		ResponseEntity<SyncDrugInformationDomain> entity=new ResponseEntity();
		try{
		BaseResponse<SyncDrugInformationDomain> returnMessage = clinicMedicationService.syncDrugInformation(syncDrugInformationPojo);
	
		entity.setCode(returnMessage.getCode());
    	entity.setMessage(returnMessage.getMessage());
		entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

		return entity;

	}
	
	@ApiOperation(value = "获取疾病诊断信息")
	@RequestMapping(value = "/syncDiagnosticInformation",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<SyncDiagnosticInformationDomain> syncDiagnosticInformation(@RequestBody  SyncDiagnosticInformationPojo syncDiagnosticInformationPojo)  {
		ResponseEntity<SyncDiagnosticInformationDomain> entity=new ResponseEntity();
		try{
		BaseResponse<SyncDiagnosticInformationDomain> returnMessage = clinicMedicationService.syncDiagnosticInformation(syncDiagnosticInformationPojo);
	
		entity.setCode(returnMessage.getCode());
    	entity.setMessage(returnMessage.getMessage());
		entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

		return entity;

	}
	
	@ApiOperation(value = "保存诊断信息")
	@RequestMapping(value = "/saveDiagnoseInformation",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<AdmNumberDomain> saveDiagnoseInformation(@RequestBody  SaveDiagnoseInformationPojo saveDiagnoseInformationPojo)  {
		ResponseEntity<AdmNumberDomain> entity=new ResponseEntity();
		try{
		BaseResponse<AdmNumberDomain> returnMessage = clinicMedicationService.saveDiagnoseInformation(saveDiagnoseInformationPojo);
	
		entity.setCode(returnMessage.getCode());
    	entity.setMessage(returnMessage.getMessage());
		entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

		return entity;

	}
	
	@ApiOperation(value = "保存处方信息")
	@RequestMapping(value = "/savePrescriptionInformation",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<SavePrescriptionInformationDomain> savePrescriptionInformation(@RequestBody @Validated SavePrescriptionInformationPojo savePrescriptionInformationPojo)  {
		ResponseEntity<SavePrescriptionInformationDomain> entity=new ResponseEntity();
		try{
		BaseResponse<SavePrescriptionInformationDomain> returnMessage = clinicMedicationService.savePrescriptionInformation(savePrescriptionInformationPojo);
	
		entity.setCode(returnMessage.getCode());
    	entity.setMessage(returnMessage.getMessage());
		entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

		return entity;

	}
	
	@ApiOperation(value = "查询门诊诊断信息")
	@RequestMapping(value = "/getDiagnoseInformation",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<List<GetDiagInfoDomain>> getDiagnoseInformation(@RequestBody  AdmNumberPojo admNumberPojo)  {
		ResponseEntity<List<GetDiagInfoDomain>> entity=new ResponseEntity();
		try{
		BaseResponse<List<GetDiagInfoDomain>> returnMessage = clinicMedicationService.getDiagnoseInformation(admNumberPojo);
	
		entity.setCode(returnMessage.getCode());
    	entity.setMessage(returnMessage.getMessage());
		entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

		return entity;

	}
	
	
	@ApiOperation(value = "查询门诊处方信息")
	@RequestMapping(value = "/getPrescriptionInformation",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<List<GetPrescriptionInformationDomain>> getPrescriptionInformation(@RequestBody  AdmNumberPojo admNumberPojo)  {
		ResponseEntity<List<GetPrescriptionInformationDomain>> entity=new ResponseEntity();
		try{
		BaseResponse<List<GetPrescriptionInformationDomain>> returnMessage = clinicMedicationService.getPrescriptionInformation(admNumberPojo);
	
		entity.setCode(returnMessage.getCode());
    	entity.setMessage(returnMessage.getMessage());
		entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

		return entity;

	}
	
	
	@ApiOperation(value = "查询门诊病历信息")
	@RequestMapping(value = "/getMedicalRecordInformation",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<List<GetMedicalRecordInformationDomain>> getMedicalRecordInformation(@RequestBody  AdmNumberPojo admNumberPojo,
																							   HttpServletRequest request)  {
		ResponseEntity<List<GetMedicalRecordInformationDomain>> entity=new ResponseEntity();
		try{
		BaseResponse<List<GetMedicalRecordInformationDomain>> returnMessage = clinicMedicationService.getMedicalRecordInformation(admNumberPojo,request);
	
		entity.setCode(returnMessage.getCode());
    	entity.setMessage(returnMessage.getMessage());
		entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

		return entity;

	}
	
	@ApiOperation(value = "获取门诊就诊记录信息")
	@RequestMapping(value = "/getVisitingRecord",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<AdmNumberDomain> getVisitingRecord(@RequestBody  GetVisitingRecordPojo getVisitingRecordPojo)  {
		ResponseEntity<AdmNumberDomain> entity=new ResponseEntity();
		try{
		BaseResponse<AdmNumberDomain> returnMessage = clinicMedicationService.getVisitingRecord(getVisitingRecordPojo);
	
		entity.setCode(returnMessage.getCode());
    	entity.setMessage(returnMessage.getMessage());
		entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

	return entity;

	}
	
	@ApiOperation(value = "更新门诊就诊记录状态")
	@RequestMapping(value = "/updateVisitStatus",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<Object> updateVisitStatus(@RequestBody UpdateVisitStatusPojo updateVisitStatusPojo)  {
		ResponseEntity<Object> entity=new ResponseEntity();
		try{
		BaseResponse<Object> returnMessage = clinicMedicationService.updateVisitStatus(updateVisitStatusPojo);
	
		entity.setCode(returnMessage.getCode());
    	entity.setMessage(returnMessage.getMessage());

		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

	return entity;

	}
	
	
	
	@ApiOperation(value = "同步药品用法信息")
	@RequestMapping(value = "/getDrugUsage",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<List<DrugUsageDomain>> getDrugUsage(@RequestBody  OrganizationIdPojo organizationIdPojo)  {
		ResponseEntity<List<DrugUsageDomain>> entity=new ResponseEntity();
		try{
		BaseResponse<List<DrugUsageDomain>> returnMessage = clinicMedicationService.getDrugUsage(organizationIdPojo);
	
		entity.setCode(returnMessage.getCode());
    	entity.setMessage(returnMessage.getMessage());
		entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

	return entity;

	}
	
	@ApiOperation(value = "获取药品频次信息")
	@RequestMapping(value = "/getDrugFrequency",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<List<DrugFrequencyDomain>> getDrugFrequency(@RequestBody  OrganizationIdPojo organizationIdPojo)  {
		ResponseEntity<List<DrugFrequencyDomain>> entity=new ResponseEntity();
		try{
		BaseResponse<List<DrugFrequencyDomain>> returnMessage = clinicMedicationService.getDrugFrequency(organizationIdPojo);
	
		entity.setCode(returnMessage.getCode());
    	entity.setMessage(returnMessage.getMessage());
		entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

	return entity;

	}
	
	@ApiOperation(value = "获取药品煎法信息")
	@RequestMapping(value = "/getDrugDecoction",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<List<GetDrugDecoctionDomain>> getDrugDecoction(@RequestBody  OrganizationIdPojo organizationIdPojo)  {
		ResponseEntity<List<GetDrugDecoctionDomain>> entity=new ResponseEntity();
		try{
		BaseResponse<List<GetDrugDecoctionDomain>> returnMessage = clinicMedicationService.getDrugDecoction(organizationIdPojo);
	
		entity.setCode(returnMessage.getCode());
    	entity.setMessage(returnMessage.getMessage());
		entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

	return entity;

	}
	/**
	 * 查询处方审核信息
	 */
	@ApiOperation(value = "查询处方审核信息")
	@RequestMapping(value = "/getPrescriptionAuditInformation",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<List<PrescriptionAuditInformation>>getPrescriptionAuditInformation(@Valid @RequestBody PrescriptionAuditInformationPojo pojo){
		ResponseEntity<List<PrescriptionAuditInformation>> entity=new ResponseEntity();
		BaseResponse<List<PrescriptionAuditInformation>> baseResponse=clinicMedicationService.getAuditInfo(pojo);
		entity.setCode(baseResponse.getCode());
		entity.setMessage(baseResponse.getMessage());
		entity.setData(baseResponse.getData());
		return entity;
	}
}
